﻿@model IEnumerable<LunchCommand.Models.Venue>

@{
    ViewBag.Title = "Venues";
}

@section styles
{
    @Styles.Render("~/Content/Venues.css")
}

<h2>Manage Venues</h2>

<p>
    @Html.ActionLink("Add New Venue", "Edit", null, htmlAttributes: new { @class = "btn btn-info" })
</p>
<table class="table">
    <tr>
        <th>
            Genre
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            Quick
        </th>
        <th class="user-count left">
            <span class="glyphicon glyphicon-ok text-success"></span>
        </th>
        <th class="user-count">
            /
        </th>
        <th class="user-count right">
            <span class="glyphicon glyphicon-remove text-danger"></span>
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Address)
        </th>
        <th>
            Visited
        </th>
        <th>
            Created By
        </th>
        <th />
    </tr>

    @foreach (var item in Model.OrderBy(m => m.Name))
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Genre.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td >
                @Html.DisplayFor(modelItem => item.IsQuick)
            </td>
            <td class="user-count left">
                <a href="#" 
                   title="@String.Join("<br/>", item.UsersWhoChose.Where(u => u.Degree == LunchCommand.Models.DegreeOfPreference.WantToGo).Select(u => u.User.Name))">
                    @item.UsersWhoChose.Count(u => u.Degree == LunchCommand.Models.DegreeOfPreference.WantToGo)
                </a>
            </td>
            <td class="user-count">
                /
            </td>
            <td class="user-count right">
                <a href="#" class="user-count"
                   title="@String.Join("<br/>", item.UsersWhoChose.Where(u => u.Degree == LunchCommand.Models.DegreeOfPreference.WillNotGo).Select(u => u.User.Name))">
                    @item.UsersWhoChose.Count(u => u.Degree == LunchCommand.Models.DegreeOfPreference.WillNotGo)
                </a>
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Address)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.LastVisitedString)
            </td>
            <td>
                @(item.CreatedBy == null ? "" : item.CreatedBy.Name)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.VenueID }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.VenueID })
            </td>
        </tr>
    }
</table>


@section scripts{
    @Styles.Render("~/Scripts/jquery-ui-tooltips/jquery-ui.css")
    @Scripts.Render("~/Scripts/jquery-ui-tooltips/jquery-ui.js")

    <script>
        $(function () {
            $("table").tooltip({
                show: {
                    effect: "slideDown",
                    delay: 250
                },
                content: function () {
                    return $(this).attr('title');
                }
            });
        })
    </script>
}
